<h1>产品分类</h1>
<div class="list-group">
  <% if (data.length>0) {%>
  <% for (var i=0; i<data.length; i++) { %>
  <div style="display: flex" id="cat-container">
  <a href="/admin/product/list/<%= data[i].id %>" class="list-group-item" style="width: 100%;">
    <%= data[i].category_name %>
  </a>
  <button class="btn btn-warning" data-catid="<%= data[i].id %>">删除</button>
  </div>
  <% } %>
  <% } %>
</div>
<h2>新建分类</h2>
<div id="add-cat">
  <form action="/admin/product/cat" method="post">
    <input type="text" name="cat_name" placeholder="类名">
    <input type="submit" class="btn btn-success" name="创建">
  </form>
</div>
<script>
  $(function () {
    $('#cat-container>button').click(function () {
      var cat = $(this).data('catid');
      console.log(cat);
      $.get('/admin/product/cat/delete/'+cat, function (callback, stat) {
        console.log(callback);
        if (callback.status == 'success') {
            alert('删除成功');
            location.reload();
        }
      })
    })
  })
</script>
